package com.sky.local_ads.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sky.local_ads.store_offers.StoreOffersList;
import com.sky.trueoffers.R;

public class BusinessOfferListAdapter extends BaseAdapter {

	private final Context context;
	private List<StoreOffersList> businessOfferList;

	public BusinessOfferListAdapter(Context context,
			List<StoreOffersList> storeArrayList) {
		this.context = context;
		businessOfferList = storeArrayList;
	}

	@Override
	public int getCount() {
		if (businessOfferList != null && businessOfferList.size() > 0) {
			return businessOfferList.size();
		}
		return 0;

	}

	@Override
	public Object getItem(int position) {
		return businessOfferList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return businessOfferList.indexOf(getItem(position));
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		if (convertView == null) {

			convertView = inflater.inflate(R.layout.store_offer_list_row,
					parent, false);
			holder = new ViewHolder();
			holder.offerTitle = (TextView) convertView
					.findViewById(R.id.offerTitleText);
			holder.offerDesc=(TextView)convertView.findViewById(R.id.offerDescText);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		StoreOffersList businessOffers = (StoreOffersList) getItem(position);
		
		if(businessOffers!=null) {
			String offerTitle="LOCAL OFFER";
			
			if(businessOffers.getOfferTitle()!=null) {
				offerTitle=businessOffers.getOfferTitle();
			}
			holder.offerTitle.setText(offerTitle);
			
			String offerDesc="";
			if(businessOffers.getOfferDescription()!=null) {
				offerDesc=businessOffers.getOfferDescription();
			}
			holder.offerDesc.setText(offerDesc);
			
		}

		

		return convertView;
	}
	public void updateAdapter(List<StoreOffersList> storeList) {
		this.businessOfferList= storeList;
		notifyDataSetChanged();
	}
	private static class ViewHolder {

		private TextView offerTitle;
		private TextView offerDesc;
	}

}
